﻿using System;
using System.Collections.Generic;
using System.Text;

namespace UtilZ.Dotnet.Ex.Communication.Net.Telnet.KeyCommands
{
    internal class F1ToF12Command : TelnetKeyCommandAbs
    {
        /**********************************
        * F1-F12功能键盘,mac-linux和windows相同
        * 
        * F1   27 - 79 - 80
        * F2   27 - 79 - 81
        * F3   27 - 79 - 82
        * F4   27 - 79 - 83
        *    
        * F5   27 - 91 - 49 - 53 - 126
        * F6   27 - 91 - 49 - 55 - 126
        * F7   27 - 91 - 49 - 56 - 126
        * F8   27 - 91 - 49 - 57 - 126
        *    
        * F9   27 - 91 - 50 - 48 - 126
        * F10  27 - 91 - 50 - 49 - 126
        * F11  27 - 91 - 50 - 51 - 126
        * F12  27 - 91 - 50 - 52 - 126
        **********************************/

        public F1ToF12Command()
              : base()
        {

        }

        protected override bool PrimitveProcess(ListenTelnetClient telnetClient, byte[] data, int revicedDataLength)
        {
            if (revicedDataLength == 3 && data[0] == 27 && data[1] == 79 && data[2] >= 80 && data[2] <= 83)
            {
                //F1-F4
                base.SendEcho(telnetClient, data, revicedDataLength);
                return true;
            }

            if (revicedDataLength == 5 && data[0] == 27 && data[1] == 91 && data[2] == 49 && data[4] == 126 && data[3] >= 53 && data[3] <= 57)
            {
                //F5-F8
                base.SendEcho(telnetClient, data, revicedDataLength);
                return true;
            }

            if (revicedDataLength == 5 && data[0] == 27 && data[1] == 91 && data[2] == 50 && data[4] == 126 && data[3] >= 48 && data[3] <= 52)
            {
                //F9-F12
                base.SendEcho(telnetClient, data, revicedDataLength);
                return true;
            }


            return false;
        }
    }
}
